<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>处方发药</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta content="telephone=no" name="format-detection">
    <meta name="x5-fullscreen" content="true">
    <meta name="full-screen" content="yes">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_363663_xo7863s0yfmbzkt9.css"
          th:href="@{http://at.alicdn.com/t/font_363663_xo7863s0yfmbzkt9.css}">
    <link rel="stylesheet" href="plugins/weui/weui.min.css" th:href="@{/static/plugins/weui/weui.min.css}">
    <link rel="stylesheet" href="plugins/jquery-weui/css/jquery-weui.css" th:href="@{/static/plugins/jquery-weui/css/jquery-weui.css}">
    <link rel="stylesheet" href="plugins/swiper/css/swiper.min.css" th:href="@{/static/plugins/swiper/css/swiper.min.css}">
    <link rel="stylesheet" href="css/style.css" th:href="@{/static/css/style.css}">
    <!--basis script-->
    <script src="plugins/adaptive.js/adaptive.js" th:src="@{/static/plugins/adaptive.js/adaptive.js}"></script>
    <script src="plugins/jquery/jquery.min.js" th:src="@{/static/plugins/jquery/jquery.min.js}"></script>
    <script src="plugins/weui/weui.js" th:src="@{/static/plugins/weui/weui.js}"></script>
    <script src="plugins/jquery-weui/js/jquery-weui.min.js"
            th:src="@{/static/plugins/jquery-weui/js/jquery-weui.min.js}"></script>
    <script src="plugins/fastclick/fastclick.js" th:src="@{/static/plugins/fastclick/fastclick.js}"></script>
    <script src="plugins/vue/vue.js" th:src="@{/static/plugins/vue/vue.js}"></script>
    <script src="plugins/vue/axios.min.js" th:src="@{/static/plugins/vue/axios.min.js}"></script>
    <script src="plugins/vue/ajax-tool.js" th:src="@{/static/plugins/vue/ajax-tool.js}"></script>
</head>
<body>

<div class="header">
    <div class="search-wrap">
        <div class="weui-search-bar" id="searchBar">
            <form class="weui-search-bar__form">
                <div class="weui-search-bar__box">
                    <i class="weui-icon-search"></i>
                    <input type="search" class="weui-search-bar__input" placeholder="搜索" required="" id="searchtext">
                    <a href="javascript:" class="weui-icon-clear" id="searchclear"></a>
                </div>
                <label class="weui-search-bar__label " id="search">
                    <i class="weui-icon-search"></i>
                    <span>搜索</span>
                </label>

            </form>
            <a href="#" class="weui-search-bar__cancel-btn" id="searchcancel">取消</a>
        </div>
    </div>
</div>
<div class="view has-navbar" id="prescription-drugs">
    <div class="page">
        <div class="weui-cells weui-cells_form">
            <div class="weui-cell weui-cell_switch">
                <div class="weui-cell__bd">当日</div>
                <div class="weui-cell__ft">
                    <input class="weui-switch" id="ntime" type="checkbox" checked @click="ntime"/>
                </div>
            </div>
        </div>
        <div class="weui-loadmore" v-show="showload">
            <i class="weui-loading"></i>
            <span class="weui-loadmore__tips">正在加载</span>
        </div>
        <div class="circums-wrap">
            <div id="list" class="circums-list">
                <a href="#" v-for="item in visitrecordlist" @click="redict(item)">
                    <div class="circums-list-a">
                        <strong>{{item.payer}}</strong>
                        <small class="pull-right">开药时间：{{item.dt}}</small>
                    </div>
                    <div class="circums-location">
                        <span class="pull-right">门诊号：{{item.patid}}</span>
                        <span class="pull-right">流水号：{{item.sn}}</span>
                        <span>性别：{{item.sex}}</span>
                        <span>年龄：{{item.years}}</span>
                    </div>
                </a>
            </div>
            <!-- 取消懒加载
            <div class="weui-loadmore">
                <i class="weui-loading"></i>
                <span class="weui-loadmore__tips">正在加载</span>
            </div> -->
        </div>
    </div>
</div>
<!--scripts-->
<script src="js/main.js"></script>
<script>
    $(function () {
        var lparam = JSON.parse(sessionStorage.getItem("login"))
        if(lparam == null){
            location.href = 'index.html'
        }
        var prescriptiondrugs = new Vue({
            el: '#prescription-drugs',
            data: {
                visitrecordlist: [],
                scontent: '',
                nows: true,
                showload: false
            },
            methods: {
                ntime: function(){
                    let aaa = $("#ntime").prop("checked");
                    if(aaa){
                        this.nows = true
                    }else{
                        this.nows = false
                    }
                    let visits = this.addvisits();
                    this.visitrecordlist.splice(0, this.visitrecordlist.length)
                    this.visitrecordlist = this.visitrecordlist.concat(visits)
                },
                addvisits: function () {
                    //TODO 查询代发药记录
                    let res = []
                    let _this = this
                    console.info(this.showload)
                    ajaxsync({
                        url: '/mph/rec/all?aid='+lparam.aid+'&now='+_this.nows+'&search='+_this.scontent,
                        method: 'get',
                        datajson: null,
                        succ: function (data) {
                            res = data.clinicRecViews
                        }
                    })
                    console.info('查询代发药记录')
                    return res
                },
                search: function () {
                    console.info('搜索功能')
                    //TODO 搜索功能
                    let visits = this.addvisits();
                    this.visitrecordlist.splice(0, this.visitrecordlist.length)
                    this.visitrecordlist = this.visitrecordlist.concat(visits)
                },
                redict: function (visitinfo) {
                    console.info('页面跳转：'+JSON.stringify(visitinfo))
                    location.href = 'prescription-drugs-detail.html?aid='+visitinfo.aid
                        +'&patid='+visitinfo.patid+'&sn='+visitinfo.sn
                }
            }
        })

        $('#search').click(function () {
            prescriptiondrugs.search()
        })

        //初始化药品列表
        function instance(){
            let visits = prescriptiondrugs.addvisits();
            prescriptiondrugs.visitrecordlist.splice(0, prescriptiondrugs.visitrecordlist.length)
            prescriptiondrugs.visitrecordlist = prescriptiondrugs.visitrecordlist.concat(visits)
        }
        instance()

        //搜索
        weui.searchBar('#searchBar');

        $('#searchtext').bind('input propertychange', function() {
            console.info('search start')
            prescriptiondrugs.scontent = $('#searchtext').val()
            prescriptiondrugs.search()
            console.info('search end')
        });

        $('#searchcancel').click(function () {
            console.info('search cancel start')
            prescriptiondrugs.scontent = ''
            prescriptiondrugs.search()
            console.info('search cancel end')
        })

        $('#searchclear').click(function () {
            prescriptiondrugs.scontent = ''
            prescriptiondrugs.search()
        })


    })
</script>
</body>
</html>
